package project.controller;

import project.entity.Grade;
import project.entity.Student;
import project.service.GradeService;
import project.service.StudentService;
import project.service.impl.GradeServiceImpl;
import project.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/*
杨威
2021/9/16
14:06
*/
@WebServlet("/selectStudent")
public class SelectStudentByIdAndGradeController extends HttpServlet {
    StudentService studentService=new StudentServiceImpl();
    GradeService gradeService=new GradeServiceImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String stuId = request.getParameter("stuId");
        Student student = studentService.showStudentById(Integer.valueOf(stuId));
        List<Grade> grades = gradeService.selectAllGrade();
        request.setAttribute("grades",grades);
        request.setAttribute("stu",student);
        request.getRequestDispatcher("update.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
